package net.libra.scrollui
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	
	import net.libra.utils.DisplayUtil;

	/**
	 * 水平布局
	 * @author 姜波
	 * @createTime 2010-12-18
	 * @version 1.0
	 * */
	public class HLayout
	{
		public static function layout(container:DisplayObjectContainer,HorizontalGap:Number):void
		{
			var children:Array = DisplayUtil.getChildren(container);
			var top:Number = 0;
			for(var i:int = 0; i < children.length; i++)
			{
				var child:DisplayObject = children[i] as DisplayObject;
				child.x = top;
				top += child.width + HorizontalGap;
			}
		}
		/**
		 * 对准中心布局
		 */ 
		public static function layout2(container:DisplayObjectContainer,HorizontalGap:Number):void
		{
			var children:Array = DisplayUtil.getChildren(container);
			var top:Number = 0;
			for(var i:int = 0; i < children.length; i++)
			{
				var child:DisplayObject = children[i] as DisplayObject;
				child.x = top;
				top += child.width + HorizontalGap;
			}
		}
		
		public static function getContentHeight(container:DisplayObjectContainer,verticalGap:Number):Number
		{
			var children:Array = DisplayUtil.getChildren(container);
			var top:Number = 0;
			for(var i:int = 0; i < children.length; i++)
			{
				var child:DisplayObject = children[i] as DisplayObject;
				top += child.height + verticalGap;
			}
			return top;
		}
	}
}